#include <stdio.h>
#include <stdlib.h>


#define LEFT 1
#define RIGHT 100
/*
 *while初识
 * */
void test1(void)
{
	int i;
	int sum = 0;
	i = LEFT;
	
	while(i <= RIGHT)
	{
	sum += i;
	i++;

	}
	printf("%d - %d sum = %d\n",LEFT,RIGHT,sum);

}



/*
 *do-while 先跑一遍再判断
 * */
void test2(void)
{
	int i = LEFT , sum = 0;
	do
	{
	sum += i;
	i++;
	}while(i<=RIGHT);

	printf("%d - %d sum = %d\n",LEFT,RIGHT,sum);


}
/*
 * start - end  sum
 * */
void test3(void)
{
	int start,end;
	int ret; 
	int sum = 0;
	printf("plz enter start And end ：\n");
	ret = scanf("%d%d",&start,&end);
	if (ret = 2)
	{
	
 		while(start <= end)
		{
			sum += start;
			start++;
		
		}	
		printf("[%d -- %d]sum = %d\n",start,end,sum);
	}else  /*else if( start >= end ||ret != 2 ) 条件设置得不好 : 符合ret = 2 后无论start与end那个大都不会进来*/
	{
		fprintf(stderr,"input error！\n");
		exit(0);
	}



}

int main(void)
{
	test1();	
	test2();
	test3();
	exit(0);
}
